//
// Created by Kai Wang on 2023/12/28.
//

#ifndef OPENCOS_ORDER_FORM_H
#define OPENCOS_ORDER_FORM_H

#include <QStringListModel>
#include <QWidget>
#include <order/order.h>
#include <string>

QT_BEGIN_NAMESPACE

namespace Ui
{
class OrderForm;
}

QT_END_NAMESPACE

class OrderForm : public QWidget
{
    Q_OBJECT

public:
    explicit OrderForm(QWidget *parent = nullptr);
    ~OrderForm() override;

public:
    void on_item_clicked(const QModelIndex &index);
    void on_order_history_clicked(const QModelIndex &index);

    void on_pointsSortedButton_clicked();
    void on_sellSortedButton_clicked();

    void on_addButton_clicked();
    void on_subButton_clicked();
    void update_with_ordered_items();

    void on_calcButton_clicked();
    void on_againButton_clicked();

private:
    Ui::OrderForm *ui;

    Order             order_;
    QStringList       cart_infos;
    QStringListModel *cart_model_ = nullptr;
    Item              current_item_;
    Order             current_order_history_;

    const std::string fmt_string         = "{0:<40}{1:>10.2f}¥ 销量 {2:<3}, 评分 {3:<.2f}";
    const std::string fmt_string_history = "订单号 {0:<10} 订单完成时间 {1:<30} 总价 {2:<.2f}";
};

#endif  // OPENCOS_ORDER_FORM_H
